<?php
namespace app\pet\controller;
use app\common\controller\Table;

Class TableCodeList extends Table
{
    protected $table_header = [
        ['key'=>'id','name'=>'编码','search'=>0],
        ['key'=>'activation_code','name'=>'激活码','search'=>1],
        ['key'=>'is_used','name'=>'是否使用','search'=>0],
    ];

    protected $excel_key = ['编码','激活码','是否使用(1已使用|0未使用)'];

    //excel处理
    public function excelUrl($key=[],$return_data=0){
        parent::excelUrl($this->excel_key,0);
    }

    public function data($page=1,$limit=10){
        parent::data($page,$limit);
        $res = $this->data;
        //可对数据整合打包发给前端
        if($res['code']==0){
            $excel = $this->excelList('common','用户激活表',
                '用户激活表',$this->count,3000,$this->where);
            $res['excel'] = $excel;
        }

        foreach ($res['data'] as $k=>$v){
            if($v['is_used']){
                $res['data'][$k]['is_used'] = '是';
            }
            else{
                $res['data'][$k]['is_used'] = '否';
            }
        }
        return json($res);//已经是结果 ajax
    }

    public function index(){
        parent::index();
        $table_pri =$this->privilege;
        $table_pri['read'] = 0;
        $table_pri['update'] = 0;
        $table_pri['delete'] = 1;
        $table_pri['create'] = 0;

        $this->assign([
            'table_header'=>$this->table_header,
            'pri'=>$table_pri
        ]);
        return $this->fetch();
    }

    public function recycleindex(){
        echo '暂未开放，请刷新！';
    }


}